package com.example.demo.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.pojo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Slf4j
@Service
public class Token {
    private static final String JZTUSERNAME = "jk998";
    private static final String JZTPASSWORD = "12b1322cb77f7a8e0036e0a5d4a7fcb8";
    private static final String JZTORGID = "O3CUM7GN6JI";

    @Autowired
    private RestTemplate restTemplate;

    public String getToken(){
        log.debug("========================开始获取token========================");
        //调用远程接口
        String url = "https://wdlm.test.jk.com/erp-api/wdlm/threePositions/login";
        String login = restTemplate.postForObject(url,new User(JZTUSERNAME,JZTPASSWORD,JZTORGID),String.class);
        JSONObject respJson = JSON.parseObject(login);
        String token = (String)respJson.get("msg");
        log.debug("获取token完成，token：{}",token);
        return token;
    }


}
